<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <!-- 搜索框 -->
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField">
          <el-col :lg="8" :xl="6">
            <el-form-item label="用户名" class="row-padding-bottom">
              <el-input
                placeholder="请输入用户名"
                clearable
                v-model="filterField.username"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="姓名" class="row-padding-bottom">
              <el-input
                placeholder="请输入姓名"
                clearable
                v-model="filterField.nickname"
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="用户类型" class="row-padding-bottom">
                <el-select
                  v-model="filterField.type"
                  placeholder="请选择"
                  clearable
                  filterable
                >
                  <el-option
                    v-for="item in typeIds"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="用户状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.enabled"
                  placeholder="请选择"
                  clearable
                  filterable
                >
                  <el-option
                    v-for="item in status"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-form-item style="margin-right: 8px">
            <a
              @click="toggleAdvanced"
              style="margin-left: 40px; color: #409eff; cursor: pointer"
              class="btnColor"
            >
              {{ advanced ? '收起' : '展开' }}
              <i
                :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
              ></i>
            </a>
            <!-- <el-button  type="primary"  icon="icon iconfont iconchazhao1"  class="commonBtn"  @click="searchList"></el-button> -->
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
          <!-- <el-form-item v-if="!isShowAdd">
            <exportBtn :dataLen="tableList.length" :filterField="filterField" api="api-s/report/export_SYS_USER"></exportBtn>
          </el-form-item> -->
          <!-- <el-form-item>
              <el-button v-if="isShowAdd" type="primary" class="commonBut saveBtn funComBut" icon="icon iconfont icontianjia"  @click="skipUserTab('add','first')">
                <span class="opetareText">新增用户</span>
              </el-button>
          </el-form-item> -->
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <div style="margin-bottom: 24px">
          <exportBtn
            :dataLen="tableList.length"
            :filterField="filterField"
            api="api-s/report/export_SYS_USER"
          ></exportBtn>
          <el-button
            v-if="isShowAdd"
            type="primary"
            class="commonBut saveBtn funComBut"
            icon="icon iconfont icontianjia"
            @click="skipUserTab('add', 'first')"
          >
            <span class="opetareText">新增用户</span>
          </el-button>
        </div>
        <!-- 表格 -->
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          v-loading="loading"
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="username"
            label="用户名"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="nickname"
            label="姓名"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="phone"
            label="手机号"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="deptmentName"
            label="部门"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="typeDesc"
            label="用户类型"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="enabledDesc"
            label="状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            label="操作"
            :formatter="formatTd"
            min-width="200"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-show="isShowDetail"
                @click="
                  skipUserTab(
                    'detail',
                    'first',
                    scope.row.id,
                    scope.row.typeDesc,
                    scope.row.bankSiteId
                  )
                "
                >查看账号</el-link
              >
              <el-link
                type="primary"
                v-show="isShowDetail"
                @click="
                  skipUserTab(
                    'detail',
                    'second',
                    scope.row.id,
                    scope.row.typeDesc,
                    scope.row.bankSiteId
                  )
                "
                >查看资料</el-link
              >
              <el-link
                type="primary"
                v-show="isShowDetail"
                @click="
                  skipUserTab(
                    'detail',
                    'third',
                    scope.row.id,
                    scope.row.typeDesc,
                    scope.row.bankSiteId
                  )
                "
                >查看角色</el-link
              >
              <span v-show="!isShowDetail">--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'userManageList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '用户管理',
      tableList: [],
      requestUrl: 'api-u/users/userlist',
      isShow: false, //列表加载
      loading: true,
      filterField: {
        username: '',
        nickname: '', //新增姓名查询
        enabled: '',
        type: '',
      },
      isShowAdd: '',
      isShowDetail: '',
      typeIds: [], //用户类型
      status: [], //用户状态
      advanced: false,
    }
  },
  created() {
    this.isShowAdd = this.$store.state.buttonLimitsArr.indexOf('user:add') > -1
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('user:detail') > -1
    this.getUsertype()
    this.getUserstatus()
  },
  mounted() {
    var that = this
    this.$nextTick(function () {
      that.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    //新增用户/查看用户/查看资料/查看角色
    skipUserTab(eventType, itemTab, id, typeDesc, bankSiteId) {
      this.$router.push({
        path: '/home/baseSettings/userManageTab',
        name: 'userManageTab',
        query: {
          eventType: eventType,
          itemTab: itemTab,
          id: id,
          bankSiteId: bankSiteId,
          typeDesc: typeDesc,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/baseSettings/userManageList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      var that = this
      this.$nextTick(function () {
        that.$refs.pagination.getTableListData()
      })
    },
    getUsertype() {
      this.axios({
        method: 'post',
        url: 'api-u/users/usertype',
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.typeIds = response.data.result
            } else {
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    getUserstatus() {
      this.axios({
        method: 'post',
        url: 'api-u/users/userstatus',
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.status = response.data.result
            } else {
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
  },
}
</script>

<style lang="less" scoped>
@import '../../../static/css/filterArea.less';
.operation {
  float: right;
  padding: 8px 12px 8px 12px;
  border-radius: 5px;
  background: rgb(0, 174, 255);
  color: white;
  font: 14px SourceHanSansCN-Medium;
  cursor: pointer;
}
.title {
  padding-left: 4px;
  padding-top: 10px;
  margin-bottom: -10px;
  font: bold 18px/50px Microsoft YaHei;
}
</style>
